package utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import app.cloudstringers.R;

public class CustomAuctionPeriodAdapter extends ArrayAdapter<String> {

	private int textViewResourceId;

	private String CURRENT_AUCTION_PERIOD = null;

	private Context context;

	private class ViewHolder {
		private TextView mTvItem;
	}

	public CustomAuctionPeriodAdapter(Context context, int textViewResourceId,
			String[] objects) {
		super(context, textViewResourceId, objects);

		this.context = context;
		this.textViewResourceId = textViewResourceId;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			LayoutInflater inflater = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = inflater.inflate(textViewResourceId, null);

			// Using view holder is really helpful for performance
			ViewHolder viewHolder = new ViewHolder();
			viewHolder.mTvItem = (TextView) convertView
					.findViewById(R.id.tv_spinner_item);

			convertView.setTag(viewHolder);
		}

		ViewHolder holder = (ViewHolder) convertView.getTag();
		// Set auction period has response from the server
		// If exists
		if (CURRENT_AUCTION_PERIOD != null) {
			holder.mTvItem.setText(CURRENT_AUCTION_PERIOD);
		} else {
			holder.mTvItem.setText(context
					.getString(R.string.default_auction_period));
		}

		return convertView;
	}

	public void setAuctionPeriod(String auctionPeriod) {
		CURRENT_AUCTION_PERIOD = auctionPeriod + " mins";
	}
}
